package com.briup.mt.service.impl;


import com.briup.mt.bean.Counsel;
import com.briup.mt.bean.CounselExample;
import com.briup.mt.dao.CounselMapper;
import com.briup.mt.service.ICounselService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;

@Service
public class CounselServiceImpl implements ICounselService {
    @Resource
    private CounselMapper counselMapper;

    @Override
    public List<Counsel> query(String question,String replay,String status) {
        CounselExample example=new CounselExample();
        if (!StringUtils.isEmpty(question)){
            example.createCriteria().andQuestionLike("%"+question+"%");
        }
        if (!StringUtils.isEmpty(replay)){
            example.createCriteria().andReplayLike("%"+replay+"%");}

        if (!StringUtils.isEmpty(status)){
            example.createCriteria().andStatusLike("%"+status+"%");
        }
        List<Counsel>list=counselMapper.selectByExample(example);
        return list;
    }

    @Override
    public void saveOrUpdate(Counsel counsel) {
        if (counsel.getId()==null){
            counselMapper.insert(counsel);
        }else {
            counselMapper.updateByPrimaryKey(counsel);
        }
    }
    @Override
    public void deleteById(long id) {counselMapper.deleteByPrimaryKey(id); }
}
